package day_2022_9_to_12.Day;

import java.util.HashSet;
import java.util.Set;

/**
 * @author haomin
 * @date 2022/09/10 09:42
 **/
public class Day8_2_Num208_Trie {
    class Trie {
        Set<String> set;
        public Trie() {
            set = new HashSet<>();
        }

        public void insert(String word) {
            set.add(word);
        }

        public boolean search(String word) {
            return set.contains(word);
        }

        public boolean startsWith(String prefix) {
            for(String s : set){
                if(s.startsWith(prefix))
                    return true;
            }
            return false;
        }
    }
}